﻿using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using SelfService.Model;
using SelfService.Model.Models;


namespace SelfService.ViewModel.SysPayVMs
{
    public partial class SysPayListVm : BasePagedListVM<SysPayView, SysPaySearcher>
    {

        protected override IEnumerable<IGridColumn<SysPayView>> InitGridHeader()
        {
            return new List<GridColumn<SysPayView>>{
                this.MakeGridHeader(x => x.PatientName),
                this.MakeGridHeader(x => x.PayTypeName),
                this.MakeGridHeader(x => x.Amount),
                this.MakeGridHeader(x => x.OutOrderNo),
                this.MakeGridHeader(x => x.SerialsNumber),
                this.MakeGridHeader(x => x.PayStatus),
                this.MakeGridHeader(x => x.RefundStatus),
                this.MakeGridHeader(x => x.PayTime),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeader(x => x.Use),
                this.MakeGridHeader(x => x.UseStatus),
                this.MakeGridHeader(x => x.IsSync),
                this.MakeGridHeader(x => x.IdCardNo),
                this.MakeGridHeader(x => x.CardNo),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPayView> GetSearchQuery()
        {
            var query = DC.Set<SysPay>()
                .CheckContain(Searcher.PatientName, x=>x.Patient.Name)
                .CheckEqual(Searcher.PayTypeId, x=>x.PayTypeId)
                .CheckContain(Searcher.OutOrderNo, x=>x.OutOrderNo)
                .CheckContain(Searcher.SerialsNumber, x=>x.SerialsNumber)
                .CheckEqual(Searcher.PayStatus, x=>x.PayStatus)
                .CheckEqual(Searcher.RefundStatus, x=>x.RefundStatus)
                .CheckEqual(Searcher.UseStatus, x => x.UseStatus)
                .CheckEqual(Searcher.IsSync, x => x.IsSync)
                .CheckEqual(Searcher.Use, x => x.Use)
                .CheckAuth(Wtm)
                .CheckBetween(Searcher.PayTime?.GetStartTime(), Searcher.PayTime?.GetEndTime(), x => x.PayTime, includeMax: false)
                .Select(x => new SysPayView
                {
				    ID = x.ID,
                    PatientName = x.Patient.Name,
                    CardNo = x.Patient.CardNo,
                    IdCardNo = x.Patient.IdCardNo,
                    PayTypeName = x.PayType.Name,
                    Amount = x.Amount,
                    OutOrderNo = x.OutOrderNo,
                    SerialsNumber = x.SerialsNumber,
                    PayStatus = x.PayStatus,
                    RefundStatus = x.RefundStatus,
                    PayTime = x.PayTime,
                    CreateTime = x.CreateTime,
                    Use = x.Use,
                    UseStatus = x.UseStatus,
                    IsSync = x.IsSync
                })
                .OrderByDescending(x => x.CreateTime);
            return query;
        }
    }

    public class SysPayView : SysPay{
        [Display(Name = "姓名")]
        public String PatientName { get; set; }
        
        [Display(Name = "支付方式")]
        public String PayTypeName { get; set; }
        
        [Display(Name = "卡号")]
        public String CardNo { get; set; }
        
        [Display(Name = "身份证号")]
        public string IdCardNo { get; set; }
    }
}

